package com.d3works.studio.web;

import com.d3works.exception.D3worksException;
import com.d3works.exception.service.TraceBackService;
import com.d3works.inject.Beans;
import com.d3works.rpc.ActionRequest;
import com.d3works.rpc.ActionResponse;
import com.d3works.studio.service.ChartRecordViewService;
import com.google.inject.Singleton;
import java.util.Map;

@Singleton
public class ChartBuilderController {

  public void viewRelatedRecord(ActionRequest request, ActionResponse response) {
    String chartName = (String) request.getContext().get("_chart");
    try {
      Map<String, Object> context = request.getContext();
      Map<String, Object> actionView =
          Beans.get(ChartRecordViewService.class).getActionView(chartName, context);
      response.setView(actionView);
    } catch (D3worksException e) {
      TraceBackService.trace(response, e);
    }
  }
}
